package cn.com.swu.mianyangapp.ui.message;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import cn.com.swu.mianyangapp.R;
import cn.com.swu.mianyangapp.databinding.FragmentMessageBinding;
import cn.com.swu.mianyangapp.ui.notifications.ListCardAdapter;
import cn.com.swu.mianyangapp.ui.notifications.TabFragment;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class MessageFragment extends Fragment {

    private FragmentMessageBinding binding;
    private ViewPager pager;
    private PageAdapter fragmentAdapter;
    private List<Fragment> fragmentList;
    private TabLayout tabLayout;
    private TabFragment fragment1,fragment2,fragment3;
    private List<String> mTitles;
    private String [] title={"发件箱","收件箱","草稿箱"};


    @SuppressLint("MissingInflatedId")
    @Nullable
    @org.jetbrains.annotations.Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        MessageViewModel messageViewModel = new ViewModelProvider(this).get(MessageViewModel.class);


        View view=inflater.inflate(R.layout.fragment_message,container,false);
        pager=view.findViewById(R.id.message_page);
        tabLayout=view.findViewById(R.id.message_tab);
        return view;
    }
    public void onActivityCreated(Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);

        fragmentList=new ArrayList<Fragment>();
        mTitles=new ArrayList<String>();
        mTitles.add(title[0]);
        fragmentList.add(new SendFragment());
        mTitles.add(title[1]);
        fragmentList.add(new RecvFragment());
        mTitles.add(title[2]);
        fragmentList.add(new DraftFragment());

        fragmentAdapter=new PageAdapter(getActivity().getSupportFragmentManager(),fragmentList,mTitles);
        pager.setAdapter(fragmentAdapter);
        tabLayout.setupWithViewPager(pager);//与ViewPage建立关系
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;}
}
